<template>
  <div class="shangpinfenlei">
    <div v-if="list.length" class="box">
      <div class="left">
        <div class="scroll_div">
          <div
            class="classify_item"
            :class="menuSelectedIndex == index ? 'active' : ''"
            v-for="(item, index) in list"
            :key="item.menuId"
            @click="menuSelectedIndex = index"
          >
            {{ item.menuName }}
          </div>
        </div>
      </div>
      <div class="right">
        <div class="shade" v-if="twoClassifyShow"></div>
        <div class="two_classify" v-if="list[menuSelectedIndex].type == 2">
          <div class="two_classify_hide" v-if="!twoClassifyShow">
            <div class="scroll_view">
              <div
                class="two_classify_item"
                :class="twoMenuSelectedIndex == index ? 'active' : ''"
                v-for="(item, index) in list[menuSelectedIndex].goodsMenuForms"
                :key="item.menuId"
                @click="twoMenuSelectedIndex = index"
              >
                {{ item.menuName }}
              </div>
            </div>
            <div class="two_classify_all">全部</div>
          </div>
          <div v-else class="two_classify_show">
            <div class="title_bar">
              <div class="title">选择分类</div>
              <div class="two_classify_btn">收起</div>
            </div>
            <div class="classify_show_box">
              <div
                class="
                  two_classify_item
                  twoMenuSelectedIndex
                  ==
                  index
                  ?
                  'active'
                  :
                  ''
                "
                :class="twoMenuSelectedIndex == index ? 'active' : ''"
                v-for="(item, index) in list[menuSelectedIndex].goodsMenuForms"
                :key="item.menuId"
              >
                {{ item.menuName }}
              </div>
            </div>
          </div>
        </div>

        <div class="goods_list">
          <div class="goods_list_item">
            <div class="two_title" v-if="list[menuSelectedIndex].type === 2">
              {{
                list[menuSelectedIndex].goodsMenuForms[twoMenuSelectedIndex]
                  .menuName
              }}
            </div>
            <div class="goods_list_box">
              <div
                class="goods_box"
                v-for="item in filterData(list[menuSelectedIndex])"
                :key="item.goodsId"
              >
                <div class="img_box">
                  <img class="image" :src="fileBaseUrl + item.coverImg" />
                </div>
                <div class="right_info">
                  <div class="title">{{ item.title }}</div>
                  <div class="right_info_bottom">
                    <div class="price">¥小程序查看</div>
                    <div class="add_btn">
                      <div class="count_box">
                        <div class="add">+</div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <ModuleNotConfig v-else />
  </div>
</template>

<script>
import { getMenu } from "@/views/wxaBuildModule/api/store";
export default {
  props: {
    module: {
      type: Object,
    },
    fileBaseUrl: {
      type: String,
    },
  },
  watch: {
    module: {
      handler() {
        this.getFetchData();
      },
      deep: true,
      immediate: true,
    },
  },
  data() {
    return {
      menuSelectedIndex: 0,
      twoMenuSelectedIndex: 0,
      list: [],
      twoClassifyShow: false,
    };
  },
  mounted() {
    this.getFetchData();
  },
  computed: {
    filterData() {
      return (item) => {
        if (item.type === 2) {
          return item.goodsMenuForms[this.twoMenuSelectedIndex].goodsList || [];
        } else {
          return item.goodsList || [];
        }
      };
    },
  },
  methods: {
    getFetchData() {
      if (!this.module.biz) return;
      const { menuIdList } = this.module.biz.params;
      if (!menuIdList || !menuIdList?.length) {this.list = []; return;}
      this.getMenu(menuIdList);
    },
    getMenu(ids) {
      getMenu(ids).then((res) => {
        const { data } = res;
        this.list = data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.shangpinfenlei {
  padding-top: 10px;
  background: #f7f7f7;
}
.box {
  display: flex;
  .left {
    flex: 1;
    display: flex;
    background-color: #f7f7f7;
    height: 440px;
    overflow: hidden;
    .scroll_div {
      .classify_item {
        &.active {
          color: #fff;
          background: #ffb72f;
        }
        display: flex;
        box-sizing: border-box;
        padding-left: 15px;
        width: 80px;
        height: 45px;
        line-height: 45px;
        font-size: 13px;
        font-weight: 500;
        color: #131313;
        opacity: 0.8;
      }
    }
  }

  .right {
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 280px;
    background: #fff;

    .shade {
      position: absolute;
      z-index: 4;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background: #050505;
      opacity: 0.3;
    }

    .two_classify {
      /* position: fixed; */
      z-index: 10;
      background: #fff;
      padding: 20px 15px 0 15px;
      width: 280px;
      box-sizing: border-box;

      .two_classify_hide {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .scroll_view {
          width: 180px;
          flex: 1;
          overflow: hidden;
          white-space: nowrap;
          .two_classify_item {
            &.active {
              background: #fe7316;
              color: #fff;
            }
            display: inline-block;
            width: 55px;
            height: 23px;
            line-height: 23px;
            margin-right: 10px;
            text-align: center;
            background: #f7f7f7;
            border-radius: 4px;
            font-size: 12px;
            color: #131313;
            opacity: 0.8;
          }
        }
        .two_classify_all {
          font-size: 13px;
          font-weight: 500;
          color: #fe7316;
        }
      }

      .two_classify_show {
        background: #fff;
        padding-bottom: 33px;
        .title_bar {
          margin-top: 5px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          .title {
            font-size: 13px;
            font-weight: bold;
            color: #131313;
          }
          .two_classify_btn {
            /* margin-top:12rpx; */
            font-size: 13px;
            font-weight: 500;
            color: #fe7316;
          }
        }
        .classify_show_box {
          margin-top: 15px;
          .two_classify_item {
            &.active {
              background: #fe7316;
              color: #fff;
            }
            display: inline-block;
            width: 55px;
            height: 23px;
            line-height: 23px;
            margin-right: 10px;
            text-align: center;
            background: #f7f7f7;
            border-radius: 4px;
            font-size: 12px;
            color: #131313;
            opacity: 0.8;
          }
          .two_classify_item:nth-child(4n) {
            margin-right: 0;
          }
          .two_classify_item:nth-child(n + 5) {
            margin-top: 10px;
          }
        }
      }
    }

    .goods_list {
      position: relative;
      width: 100%;

      .goods_list_item {
        .two_title {
          background: #ffffff;
          padding: 16px 20px 6px;
        }

        .goods_list_box {
          padding-top: 10px;
          padding-left: 20px;
          .goods_box {
            display: flex;
            margin-bottom: 20px;
            .img_box {
              position: relative;
              width: 65px;
              height: 65px;
              border-radius: 7px;
              overflow: hidden;
              margin-right: 10px;
              .image {
                width: 65px;
                height: 65px;
              }
              .not_goods {
                position: absolute;
                bottom: 0;
                width: 65px;
                height: 17px;
                background: rgba(0, 0, 0, 0.5);
                font-size: 12px;
                font-family: PingFang SC;
                font-weight: 500;
                color: #ffffff;
                line-height: 16px;
                text-align: center;
              }
            }
            .right_info {
              width: 180px;
              display: flex;
              flex-direction: column;
              justify-content: space-between;

              .title {
                width: 165px;
                font-size: 16px;
                font-family: PingFang SC;
                font-weight: bold;
                color: #131313;
                white-space: nowrap;
                text-overflow: ellipsis;
                overflow: hidden;
              }
              .right_info_bottom {
                display: flex;
                justify-content: space-between;
                align-items: flex-end;
                .price {
                  font-size: 14px;
                  font-family: PingFang SC;
                  font-weight: bold;
                  color: #fe7316;
                }
                .add_btn {
                  .count_box {
                    display: flex;
                    align-items: center;
                    font-weight: bold;

                    .add {
                      font-size: 15px;
                      text-align: center;
                      width: 20px;
                      height: 20px;
                      line-height: 20px;
                      color: #fff;
                      background: #ffb72f;
                      border-radius: 50%;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
